/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.jobmesmanage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.common.enums.CampusinfoOrderStat;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.JobLink;
import com.lczyfz.campusinfo.modules.jobmesmanage.service.JobLinkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.JobMesSearch;
import com.lczyfz.campusinfo.modules.jobmesmanage.service.JobMesSearchService;

import java.util.List;

/**
 * 就业查询Controller
 * @author zms1
 * @version 2018-03-31
 */
@Controller
@RequestMapping(value = "${adminPath}/jobmesmanage/jobMesSearch")
public class JobMesSearchController extends BaseController {
	@Autowired
	private JobLinkService jobLinkService;
	@Autowired
	private JobMesSearchService jobMesSearchService;
	
	@ModelAttribute
	public JobMesSearch get(@RequestParam(required=false) String id) {
		JobMesSearch entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = jobMesSearchService.get(id);
		}
		if (entity == null){
			entity = new JobMesSearch();
		}
		return entity;
	}
	
	@RequiresPermissions("jobmesmanage:jobMesSearch:view")
	@RequestMapping(value = {"list", ""})
	public String list(JobMesSearch jobMesSearch, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JobMesSearch> page = jobMesSearchService.findPage(new Page<JobMesSearch>(request, response), jobMesSearch);
		List<JobMesSearch> jobMesSearches= jobMesSearchService.findList(jobMesSearch);
		model.addAttribute("jobMesSearches", jobMesSearches);
		model.addAttribute("page", page);
		return "modules/campusinfostu/jobMesSearchList";
	}

	@RequiresPermissions("jobmesmanage:jobMesSearch:view")
	@RequestMapping(value = "form")
	public String form(JobMesSearch jobMesSearch, Model model) {
		model.addAttribute("jobMesSearch", jobMesSearch);
		return "modules/campusinfostu/jobMesSearchForm";
	}
	@RequiresPermissions("jobmesmanage:jobMesSearch:view")
	@RequestMapping(value = "detail")
	public String detail(JobMesSearch jobMesSearch,HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<JobMesSearch> page = jobMesSearchService.findPage(new Page<JobMesSearch>(request, response), jobMesSearch);
		List<JobMesSearch> jobMesSearches= jobMesSearchService.findList(jobMesSearch);
		model.addAttribute("page", page);
		model.addAttribute("jobMesSearches", jobMesSearches);
		return "modules/campusinfostu/jobMesSearchList";
	}
	@RequiresPermissions("jobmesmanage:jobLink:edit")
	@RequestMapping(value = "delete")
	public String delete(JobLink jobLink, RedirectAttributes redirectAttributes) {
		System.out.println("查看"+jobLink.getId());
		jobLinkService.delete(jobLink);
		addMessage(redirectAttributes, "删除就业报名成功");
		return "redirect:"+Global.getAdminPath()+"/jobmesmanage/jobMesSearch/?repage";
	}
	@RequiresPermissions("jobmesmanage:jobLink:edit")
	@RequestMapping(value = "status")
	public String status(JobLink jobLink, RedirectAttributes redirectAttributes) {
		jobLink.setEnrollStatus(CampusinfoOrderStat.DONE.getValue());
		jobLinkService.status(jobLink);
		addMessage(redirectAttributes, "审核成功");
	    return "redirect:"+Global.getAdminPath()+"/jobmesmanage/jobMesSearch/?repage";
	}

}